﻿using IOP.SgrA;
using IOP.SgrA.SilkNet.Vulkan;
using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace VkSample412
{
    public class WindowConfig : IWindowConfig<Window, VulkanGraphicsManager>
    {
        public Task Config(Window window, VulkanGraphicsManager graphics)
        {
            var windowOption = window.Option;
            var lDevice = graphics.VulkanDevice;
            var swapchain = lDevice.CreateDefaultSwapChain(window).CreateDefaultSwapChainImageViews();
            var dImage = graphics.CreateDepthBufferFromConfiguration();
            var pass = graphics.CreateSwapchainRenderPassFromConfiguration(lDevice, "main", swapchain, new Format[] { Format.D16Unorm });
            pass.ConfigBeginInfo((option) =>
            {
                option.RenderArea = new Rect2D { Extent = new Extent2D(windowOption.Width, windowOption.Height), Offset = new Offset2D { X = 0, Y = 0 } };
                option.ClearValues = new ClearValue[] 
                {
                    new ClearValue() { Color = new ClearColorValue(0.2f, 0.2f, 0.2f, 0.2f) },
                    new ClearValue() { DepthStencil = new ClearDepthStencilValue(1.0f, 0) }
                };
            });
            pass.CreateSwapchainFrameBuffer(swapchain, new VulkanImageView[] { dImage }, windowOption.Height, windowOption.Width);
            var i = lDevice.CreateSemaphore(ArrangeConstant.ImageAvailableSemaphore);
            var f = lDevice.CreateSemaphore(ArrangeConstant.RenderFinishSemaphore);
            window.CreateVulkanRenderDispatcher(lDevice.WorkQueues[0], swapchain, pass, i, f);
            return Task.CompletedTask;
        }

        public void Initialization()
        {
        }
    }
}
